local p = {}
local getArgs = require('Module:Arguments').getArgs
local inArray = require('Module:Util').inArray
local OrderedTable = require('Module:OrderedTable')

local ELEMENT_MAP = require('Module:Util/Config').ELEMENT_MAP
local RARITY_NAME_MAP = require('Module:Util/Config').RARITY_MAP 
local split_swap = require('Module:Util/SwapImages').split_swap
local summon_map = require('Module:Util/Summon')

-----------------------------------------------------------------------------
-- 读取角色信息
-----------------------------------------------------------------------------

function p.query_data(summon_id)
	local card_info = summon_map[''..summon_id or ''] or ''
	card_info.id = summon_id
	return card_info
end

-----------------------------------------------------------------------------
-- 生成角色表格
-----------------------------------------------------------------------------

function p.left(frame)
	local args = getArgs(frame)
	local summon_id = tonumber(mw.text.split(args.pagename, '/')[2]) or tonumber(args.pagename)
	if not summon_id then
		return '【错误】提供的ID有错误'
	end
	
	local card_info = p.query_data(summon_id or '')

	if card_info == '' then
		return '【错误】没有找到ID相同的回响信息，请到回响列表进行更新修正。'
	end

	mw.ext.displaytitle.set(card_info.name)
	
	local half_html = '<div class="role-box element-'..(card_info.element or '0')..'"><div class="role-left">'
	
	local html = mw.html.create():tag('div'):addClass('role-base-info')
	
	local title = html:tag('div'):addClass('role-base-title color-box color-frame')
	title:tag('div'):wikitext('['..(card_info.prefix or '')..']'):done()
	title:tag('div'):wikitext(card_info.name or ''):done()
	title:done()
	
	local imgBox = html:tag('div'):addClass('role-base-img-box')
	--立绘
	
	local zoom_img_div = imgBox:tag('div'):addClass('role-base-img-group')
	local zoom_div = zoom_img_div:tag('div'):addClass('role-base-img'):attr('data-id', dataid)
	zoom_div:wikitext('[[File:'..(card_info.id or '')..'.png]]')

	return half_html..tostring(html)
end


function p.right(frame)
	local args = getArgs(frame)
	local summon_id = tonumber(mw.text.split(args.pagename, '/')[2]) or tonumber(args.pagename)
	if not summon_id then
		return '【错误】提供的ID有错误'
	end
	
	local card_info = p.query_data(summon_id or '')

	if card_info == '' then
		return '【错误】没有找到ID相同的虚构体信息，请到虚构体列表进行更新修正。'
	end
	
	local half_html = '</div><div class="role-right"><div class="role-info color-box color-frame">'
	
	local html = mw.html.create()
	html:tag('div'):addClass('role-right-title'):wikitext('基本信息'):done()
	html:tag('div'):addClass('role-right-box-2 color-frame-2'):tag('div'):addClass('role-right-box-title'):wikitext('属性'):done():tag('div'):addClass('role-right-box-content'):wikitext('[[File:Element_'..(card_info.element or '')..'.png|25px]]'..(ELEMENT_MAP[(card_info.element or '')] or '')):done():done()
	html:tag('div'):addClass('role-right-box-2 color-frame-2'):tag('div'):addClass('role-right-box-title'):wikitext('初始能量'):done():tag('div'):addClass('role-right-box-content'):wikitext(card_info.energy or ''):done():done()
	html:tag('div'):addClass('role-right-box color-frame'):tag('div'):addClass('role-right-box-title'):wikitext('加入时间'):done():tag('div'):addClass('role-right-box-content'):wikitext((os.date("%Y年%m月%d日",card_info.addDate) or '')):done():done()
	html:tag('div'):addClass('role-right-box color-frame'):tag('div'):addClass('role-right-box-title'):wikitext('英文名'):done():tag('div'):addClass('role-right-box-content'):wikitext(card_info.enName):done():done()
	html:tag('div'):addClass('role-right-box color-frame'):tag('div'):addClass('role-right-box-title'):wikitext('追忆起源'):done():tag('div'):addClass('role-right-box-content'):wikitext(card_info.description):done():done()
	html:tag('div'):addClass('role-right-box color-frame'):tag('div'):addClass('role-right-box-title'):wikitext('机神传说'):done():tag('div'):addClass('role-right-box-content'):wikitext(card_info.data):done():done()

	return half_html..tostring(html)..'</div></div></div>'
end

return p
